package com.starry.home.viewmodel.main

import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.switchMap
import com.starry.core.viewmodel.BaseViewModel
import com.starry.home.R
import com.starry.home.logic.model.main.UIUserInfo
import com.starry.home.logic.network.Repository

class MainViewModel : BaseViewModel() {


    private val _bannerUrls: MutableLiveData<ArrayList<String>> = MutableLiveData(
        arrayListOf(
            "https://starrylixu.oss-cn-beijing.aliyuncs.com/picgo/202401311709547.jpg",
            "https://starrylixu.oss-cn-beijing.aliyuncs.com/picgo/202401311709592.jpg",
            "https://starrylixu.oss-cn-beijing.aliyuncs.com/picgo/202401311710003.jpg",
            "https://starrylixu.oss-cn-beijing.aliyuncs.com/picgo/202401311710724.jpg",
            "https://starrylixu.oss-cn-beijing.aliyuncs.com/picgo/202401311710585.jpg",
        )
    )

    private val _icons: MutableLiveData<List<UIUserInfo>> = MutableLiveData(
        arrayListOf(
            UIUserInfo("个人资料", R.drawable.ic_person),
            UIUserInfo("智能问诊", R.drawable.ic_ai),
            UIUserInfo("版本信息", R.drawable.ic_version),
            UIUserInfo("用户隐私", R.drawable.ic_user),
        )
    )


    val icons: LiveData<List<UIUserInfo>> = _icons

    fun onBannerUrlsChanged(bannerUrls: ArrayList<String>) {
        _bannerUrls.value = bannerUrls
    }

    fun onIconsChanged(icons: List<UIUserInfo>) {
        _icons.value = icons
    }

    private val _userIdLiveData = MutableLiveData<Int>()
    private val _recentlyLiveData = MutableLiveData<Int>()
    val userInfo = _userIdLiveData.switchMap { userId -> Repository.getUserInfo(userId) }
    val recently =
        _recentlyLiveData.switchMap { userId -> Repository.getGhListByHzIdAndWeek(userId) }

    fun getUserInfo(userId: Int) {
        _userIdLiveData.value = userId
    }

    fun getRecently(userId: Int) {
        _recentlyLiveData.value = userId
    }
}